package com.acwing.partition34;

import java.io.*;
import java.util.HashMap;
import java.util.Map;

/**
 * @author `RKC`
 * @date 2022/3/19 9:48
 */
public class AC3370牛年 {

    private static Map<String, Integer> seqMap = new HashMap<>(), map = new HashMap<>();

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    static {
        seqMap.put("Ox", 0);
        seqMap.put("Tiger", 1);
        seqMap.put("Rabbit", 2);
        seqMap.put("Dragon", 3);
        seqMap.put("Snake", 4);
        seqMap.put("Horse", 5);
        seqMap.put("Goat", 6);
        seqMap.put("Monkey", 7);
        seqMap.put("Rooster", 8);
        seqMap.put("Dog", 9);
        seqMap.put("Pig", 10);
        seqMap.put("Rat", 11);
        map.put("Bessie", 0);
    }

    public static void main(String[] args) throws IOException {
        int n = Integer.parseInt(reader.readLine());
        while (n-- > 0) {
            String[] ss = reader.readLine().split(" ");
            String a = ss[0], b = ss[7], rel = ss[3];
            int cnt = seqMap.get(ss[4]), q = map.get(b);
            if ("previous".equals(rel)) {
                int x = ((q - cnt) % 12 + 12) % 12;
                if (x == 0) x = 12;
                map.put(a, q - x);
            } else {
                int x = ((cnt - q) % 12 + 12) % 12;
                if (x == 0) x = 12;
                map.put(a, q + x);
            }
        }
        writer.write(Math.abs(map.get("Elsie")) + "\n");
        writer.flush();
    }
}
